package jtp.controller;

import com.alibaba.fastjson.JSON;

import jtp.bean.Profiletags;
import jtp.mapper.TrafficChannelStatsService;
import jtp.utils.DateUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/jtp/traffic")
public class TrafficController {
    @Autowired
    private TrafficChannelStatsService trafficChannelStatsService;
    private static final String DATE_DEFAULT_VALUE = "1970-07-01";
    @RequestMapping("/channe/am")
    public String getChannelPv(@RequestParam  (value = "date",defaultValue = DATE_DEFAULT_VALUE) String date) {
        if (date.equals(DATE_DEFAULT_VALUE)){
            date = DateUtil.nowDate();
        }
        List<Profiletags> trafficChannelAmBeans = trafficChannelStatsService.selectAmCount(date);
        if (trafficChannelAmBeans==null||trafficChannelAmBeans.isEmpty()){
            return "[]";
        }
        return JSON.toJSONString(trafficChannelAmBeans);
    }
 }
